package vote.ai.service.Impl;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;
import vote.ai.constant.PromptConstant;
import vote.ai.service.AiCorrectionService;

/**
 * Description:阿里千问模型AI纠错
 * Author:han
 * Date: 2024-05-21
 */
@ConditionalOnProperty(prefix = "spring.ai.dashscope",name = "enabled",havingValue = "true")
@Service("tongyiCorrectionService")
public class AliyunAICorrection implements AiCorrectionService {
    private final ChatModel chatModel;
    private final ChatClient chatClient;
    public AliyunAICorrection(ChatModel chatModel) {
        this.chatModel = chatModel;
        this.chatClient=ChatClient.builder(chatModel).build();
    }
    @Override
    public String correction(String text, String taskId) {
        return this.chatClient.prompt(PromptConstant.WORD_CORRECTION+text)
                .call()//返回结果应该不是流式输出的吧
                .content();
    }
}
